import * as mongoose from 'mongoose';
import config from 'src/config';

export function createConnectUrl(){
	var url=""
	if(config.db.username&&config.db.password){
		url=`mongodb://${config.db.username}:${config.db.password}@${config.db.host}:${config.db.port||27017}/${config.db.dbname}`
	}else{
		url=`mongodb://${config.db.host}:${config.db.port||27017}/${config.db.dbname}`
	}
	return url
}
export const databaseProviders = [
	{
		provide: 'DATABASE_CONNECTION',
		useFactory: (): Promise<typeof mongoose> =>mongoose.connect(createConnectUrl(),{minPoolSize:50,maxPoolSize:500,maxConnecting:50,directConnection:true}),
	},
];
